---------------------------------------------------------------------------------
       log:  C:\papers\formateur\changepm.log
  log type:  text
 opened on:  13 Nov 2010, 01:25:27

. #delimit ;
delimiter now ;
. set mem 30m;
(30720k)

. /*clear matrix;*/
> /*clear mata; */
> 
> set more off;

. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:  stata_mxl_predictprob.do                            *;
. *       Date:       November 9, 2010                                    *;
. *       Author:     GG/MG                                               *;
. *       Purpose:    Produce Tables 1 and 2 in AJPS paper                *;
. *       Input File:     europe.dta                                      *;
. *       Output File:    stata_mxl_predictprob.log                       *;
. *       Data Output:    none                                            *;
. *       Previous file:  europe.dta                                      *;
. *       Machine:        Matt's desktop                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. use "europe.dta", clear;

. *     ****************************************************************  *;
. *       Model 6: Western Europe                                         *;
. *     ****************************************************************  *;
. mixlogit choice largestparty_east party_seatshare_east medianparty1_east pres
> identparty_east previousPM_east previousPM_conflict_east previousPM_gain1_eas
> t previous_cabinet_gain1_east,  
>     rand (largestparty party_seatshare medianparty1 presidentparty previousPM
>  president_investiture president_direct previousPM_conflict previousPM_gain1 
> previous_cabinet_gain1) 
>     ln(0) nrep(125) group(cabinetcode);

Iteration 0:   log likelihood = -255.29786  (not concave)
Iteration 1:   log likelihood = -245.38797  (not concave)
Iteration 2:   log likelihood =  -228.8695  
Iteration 3:   log likelihood = -221.24204  (not concave)
Iteration 4:   log likelihood = -221.16184  (not concave)
Iteration 5:   log likelihood = -220.39987  
Iteration 6:   log likelihood = -219.61402  
Iteration 7:   log likelihood = -219.46931  
Iteration 8:   log likelihood = -219.42816  (not concave)
Iteration 9:   log likelihood = -219.41127  (not concave)
Iteration 10:  log likelihood = -219.40734  (not concave)
Iteration 11:  log likelihood = -219.38014  
Iteration 12:  log likelihood = -219.35916  
Iteration 13:  log likelihood = -219.35268  
Iteration 14:  log likelihood = -219.35266  

Mixed logit model                                 Number of obs   =       2039
                                                  LR chi2(10)     =      19.54
Log likelihood = -219.35266                       Prob > chi2     =     0.0339

------------------------------------------------------------------------------
      choice |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Mean         |
largestp~ast |  -1.253544   2.017873    -0.62   0.534    -5.208503    2.701414
party_se~ast |   .2877481   .1444587     1.99   0.046     .0046143    .5708819
medianpa~ast |  -3.117227   1.721757    -1.81   0.070    -6.491809    .2573546
presi~y_east |  -.4970681   1.853252    -0.27   0.789    -4.129376     3.13524
previ~M_east |   -2.19965   2.606521    -0.84   0.399    -7.308337    2.909037
previ~t_east |   1.126725   3.208478     0.35   0.725    -5.161776    7.415226
previousPM.. |  -.0930831   .4810077    -0.19   0.847    -1.035841    .8496747
previous_c.. |   .0517841   .1988117     0.26   0.795    -.3378797    .4414479
largestparty |   2.109019   1.104417     1.91   0.056    -.0555996    4.273637
party_seat~e |   .1351541   .0258657     5.23   0.000     .0844583    .1858499
medianparty1 |   1.392319   .3828235     3.64   0.000     .6419985    2.142639
presidentp~y |   5.250695   2.428888     2.16   0.031      .490162    10.01123
  previousPM |   2.841572   1.038968     2.73   0.006     .8052325    4.877912
president_~e |  -3.060496   2.130412    -1.44   0.151    -7.236027    1.115035
president~ct |  -3.915977     2.1442    -1.83   0.068    -8.118531    .2865775
previousP~ct |  -2.618633   1.261868    -2.08   0.038    -5.091848   -.1454174
previousPM~1 |   .4958572   .2007184     2.47   0.013     .1024564     .889258
previous_c~1 |   .0367127   .0403208     0.91   0.363    -.0423147    .1157401
-------------+----------------------------------------------------------------
SD           |
largestparty |   -4.72622   1.779758    -2.66   0.008    -8.214482   -1.237957
party_seat~e |  -.0074871   .0352742    -0.21   0.832    -.0766233    .0616491
medianparty1 |    .137813   .9798871     0.14   0.888     -1.78273    2.058357
presidentp~y |   -.266903   1.275177    -0.21   0.834    -2.766204    2.232398
  previousPM |   -1.90488   1.048407    -1.82   0.069     -3.95972    .1499603
president_~e |  -.4246113   1.592647    -0.27   0.790    -3.546143     2.69692
president~ct |    .591708    1.45034     0.41   0.683    -2.250906    3.434321
previousP~ct |  -.1339581   2.773063    -0.05   0.961    -5.569061    5.301145
previousPM~1 |     .11201   .2052589     0.55   0.585      -.29029      .51431
previous_c~1 |   .1484155   .0862285     1.72   0.085    -.0205892    .3174201
------------------------------------------------------------------------------

.     *     ****************************************************************  *
> ;
. *       Now produce Figure 1                                            *;
. *     ****************************************************************  *;
. matrix coeffs = e(b);

. matrix covmat = e(V);

. keep if cabinetcode==1222;
(2400 observations deleted)

. set obs 10000;
obs was 12, now 10000

. generate pvda = 0;

. replace pvda = 1 if partyID==7;
(1 real change made)

. generate cda = 0;

. replace cda = 1 if partyID==13;
(1 real change made)

. generate vvd = 0;

. replace vvd = 1 if partyID==22;
(1 real change made)

. generate d66 = 0;

. replace d66 = 1 if partyID==10;
(1 real change made)

. generate ppvda1 = .;
(10000 missing values generated)

. generate pcda1 = .;
(10000 missing values generated)

. generate pvvd1 = .;
(10000 missing values generated)

. generate pd661 = .;
(10000 missing values generated)

. generate ppvda2 = .;
(10000 missing values generated)

. generate pcda2 = .;
(10000 missing values generated)

. generate pvvd2 = .;
(10000 missing values generated)

. generate pd662 = .;
(10000 missing values generated)

. generate ppvda3 = .;
(10000 missing values generated)

. generate pcda3 = .;
(10000 missing values generated)

. generate pvvd3 = .;
(10000 missing values generated)

. generate pd663 = .;
(10000 missing values generated)

. generate ppvda4 = .;
(10000 missing values generated)

. generate pcda4 = .;
(10000 missing values generated)

. generate pvvd4 = .;
(10000 missing values generated)

. generate pd664 = .;
(10000 missing values generated)

. drawnorm b1-b28, means(coeffs) cov(covmat) double;

.  nois _dots 0, title(largest party sim) reps(10000);
largest party sim (10000)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 

. forvalues j = 1/10000 {;
  2.   mkmat b1-b28 if _n==`j', matrix(bdraw);
  3.   mixlpred2 pprobs;
  4.    qui generate pt1 = pprobs * pvda;
  5.   qui generate ct1 = pprobs * cda;
  6.   qui generate vt1 = pprobs * vvd;
  7.   qui generate dt1 = pprobs * d66;
  8.   qui replace previousPM = 1 if pvda==1;
  9.   qui replace previousPM_gain1 = -13.33333 if pvda==1;
 10.   qui replace previous_cabinet_gain1 = -7.333344 if pvda==1;
 11.   qui replace previousPM = 0 if cda==1;
 12.   qui replace previousPM_gain1 = 0 if cda==1;
 13.   qui replace previous_cabinet_gain1 = 0 if cda==1;
 14. mixlpred2 pprobs2;
 15.   qui generate pt2 = pprobs2 * pvda;
 16.   qui generate ct2 = pprobs2 * cda;
 17.   qui generate vt2 = pprobs2 * vvd;
 18.   qui generate dt2 = pprobs2 * d66;
 19.   qui replace previousPM = 1 if vvd==1;
 20.   qui replace previousPM_gain1 = -13.33333 if vvd==1;
 21.   qui replace previous_cabinet_gain1 = -7.333344 if vvd==1;
 22.   qui replace previousPM = 0 if pvda==1;
 23.   qui replace previousPM_gain1 = 0 if pvda==1;
 24.   qui replace previous_cabinet_gain1 = 0 if pvda==1;
 25. mixlpred2 pprobs3;
 26.   qui generate pt3 = pprobs3 * pvda;
 27.   qui generate ct3 = pprobs3 * cda;
 28.   qui generate vt3 = pprobs3 * vvd;
 29.   qui generate dt3 = pprobs3 * d66;
 30.   qui replace previousPM = 1 if d66==1;
 31.   qui replace previousPM_gain1 = -13.33333 if d66==1;
 32.   qui replace previous_cabinet_gain1 = -7.333344 if d66==1;
 33.   qui replace previousPM = 0 if vvd==1;
 34.   qui replace previousPM_gain1 = 0 if vvd==1;
 35.   qui replace previous_cabinet_gain1 = 0 if vvd==1;
 36. mixlpred2 pprobs4;
 37.   qui generate pt4 = pprobs4 * pvda;
 38.   qui generate ct4 = pprobs4 * cda;
 39.   qui generate vt4 = pprobs4 * vvd;
 40.   qui generate dt4 = pprobs4 * d66;
 41.   qui replace previousPM = 1 if cda==1;
 42.   qui replace previousPM_gain1 = -13.33333 if cda==1;
 43.   qui replace previous_cabinet_gain1 = -7.333344 if cda==1;
 44.   qui replace previousPM = 0 if d66==1;
 45.   qui replace previousPM_gain1 = 0 if d66==1;
 46.   qui replace previous_cabinet_gain1 = 0 if d66==1;
 47.   egen pt1s = sum(pt1);
 48.   egen ct1s = sum(ct1);
 49.   egen vt1s = sum(vt1);
 50.   egen dt1s = sum(dt1);
 51.   egen pt2s = sum(pt2);
 52.   egen ct2s = sum(ct2);
 53.   egen vt2s = sum(vt2);
 54.   egen dt2s = sum(dt2);
 55.   egen pt3s = sum(pt3);
 56.   egen ct3s = sum(ct3);
 57.   egen vt3s = sum(vt3);
 58.   egen dt3s = sum(dt3);
 59.   egen pt4s = sum(pt4);
 60.   egen ct4s = sum(ct4);
 61.   egen vt4s = sum(vt4);
 62.   egen dt4s = sum(dt4);
 63.   qui replace ppvda1 = pt1s if _n==`j';
 64.   qui replace pcda1 = ct1s if _n==`j';
 65.   qui replace pvvd1 = vt1s if _n==`j';
 66.   qui replace pd661 = dt1s if _n==`j';
 67.   qui replace ppvda2 = pt2s if _n==`j';
 68.   qui replace pcda2 = ct2s if _n==`j';
 69.   qui replace pvvd2 = vt2s if _n==`j';
 70.   qui replace pd662 = dt2s if _n==`j';
 71.   qui replace ppvda3 = pt3s if _n==`j';
 72.   qui replace pcda3 = ct3s if _n==`j';
 73.   qui replace pvvd3 = vt3s if _n==`j';
 74.   qui replace pd663 = dt3s if _n==`j';
 75.   qui replace ppvda4 = pt4s if _n==`j';
 76.   qui replace pcda4 = ct4s if _n==`j';
 77.   qui replace pvvd4 = vt4s if _n==`j';
 78.   qui replace pd664 = dt4s if _n==`j';
 79. drop pt1 ct1 vt1 dt1 pt2 ct2 vt2 dt2 pt3 ct3 vt3 dt3 pt4 ct4 vt4 dt4 
> pt1s ct1s vt1s dt1s pt2s ct2s vt2s dt2s pt3s ct3s vt3s dt3s pt4s ct4s vt4s dt
> 4s 
> pprobs pprobs2 pprobs3 pprobs4;
 80.  nois _dots `j' 0;
 81.   };
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500
..................................................   550
..................................................   600
..................................................   650
..................................................   700
..................................................   750
..................................................   800
..................................................   850
..................................................   900
..................................................   950
..................................................  1000
..................................................  1050
..................................................  1100
..................................................  1150
..................................................  1200
..................................................  1250
..................................................  1300
..................................................  1350
..................................................  1400
..................................................  1450
..................................................  1500
..................................................  1550
..................................................  1600
..................................................  1650
..................................................  1700
..................................................  1750
..................................................  1800
..................................................  1850
..................................................  1900
..................................................  1950
..................................................  2000
..................................................  2050
..................................................  2100
..................................................  2150
..................................................  2200
..................................................  2250
..................................................  2300
..................................................  2350
..................................................  2400
..................................................  2450
..................................................  2500
..................................................  2550
..................................................  2600
..................................................  2650
..................................................  2700
..................................................  2750
..................................................  2800
..................................................  2850
..................................................  2900
..................................................  2950
..................................................  3000
..................................................  3050
..................................................  3100
..................................................  3150
..................................................  3200
..................................................  3250
..................................................  3300
..................................................  3350
..................................................  3400
..................................................  3450
..................................................  3500
..................................................  3550
..................................................  3600
..................................................  3650
..................................................  3700
..................................................  3750
..................................................  3800
..................................................  3850
..................................................  3900
..................................................  3950
..................................................  4000
..................................................  4050
..................................................  4100
..................................................  4150
..................................................  4200
..................................................  4250
..................................................  4300
..................................................  4350
..................................................  4400
..................................................  4450
..................................................  4500
..................................................  4550
..................................................  4600
..................................................  4650
..................................................  4700
..................................................  4750
..................................................  4800
..................................................  4850
..................................................  4900
..................................................  4950
..................................................  5000
..................................................  5050
..................................................  5100
..................................................  5150
..................................................  5200
..................................................  5250
..................................................  5300
..................................................  5350
..................................................  5400
..................................................  5450
..................................................  5500
..................................................  5550
..................................................  5600
..................................................  5650
..................................................  5700
..................................................  5750
..................................................  5800
..................................................  5850
..................................................  5900
..................................................  5950
..................................................  6000
..................................................  6050
..................................................  6100
..................................................  6150
..................................................  6200
..................................................  6250
..................................................  6300
..................................................  6350
..................................................  6400
..................................................  6450
..................................................  6500
..................................................  6550
..................................................  6600
..................................................  6650
..................................................  6700
..................................................  6750
..................................................  6800
..................................................  6850
..................................................  6900
..................................................  6950
..................................................  7000
..................................................  7050
..................................................  7100
..................................................  7150
..................................................  7200
..................................................  7250
..................................................  7300
..................................................  7350
..................................................  7400
..................................................  7450
..................................................  7500
..................................................  7550
..................................................  7600
..................................................  7650
..................................................  7700
..................................................  7750
..................................................  7800
..................................................  7850
..................................................  7900
..................................................  7950
..................................................  8000
..................................................  8050
..................................................  8100
..................................................  8150
..................................................  8200
..................................................  8250
..................................................  8300
..................................................  8350
..................................................  8400
..................................................  8450
..................................................  8500
..................................................  8550
..................................................  8600
..................................................  8650
..................................................  8700
..................................................  8750
..................................................  8800
..................................................  8850
..................................................  8900
..................................................  8950
..................................................  9000
..................................................  9050
..................................................  9100
..................................................  9150
..................................................  9200
..................................................  9250
..................................................  9300
..................................................  9350
..................................................  9400
..................................................  9450
..................................................  9500
..................................................  9550
..................................................  9600
..................................................  9650
..................................................  9700
..................................................  9750
..................................................  9800
..................................................  9850
..................................................  9900
..................................................  9950
.................................................. 10000

. generate pvdad2 = ppvda2 - ppvda1;

. generate pvdad3 = ppvda3 - ppvda1;

. generate pvdad4 = ppvda4 - ppvda1;

. generate cdad2 = pcda2 - pcda1;

. generate cdad3 = pcda3 - pcda1;

. generate cdad4 = pcda4 - pcda1;

. generate vvdd2 = pvvd2 - pvvd1;

. generate vvdd3 = pvvd3 - pvvd1;

. generate vvdd4 = pvvd4 - pvvd1;

. generate d66d2 = pd662 - pd661;

. generate d66d3 = pd663 - pd661;

. generate d66d4 = pd664 - pd661;

. summarize 
> ppvda1 pcda1 pvvd1 pd661
> ppvda2 pcda2 pvvd2 pd662
> ppvda3 pcda3 pvvd3 pd663
> ppvda4 pcda4 pvvd4 pd664
> pvdad2 cdad2 vvdd2 d66d2
> pvdad3 cdad3 vvdd3 d66d3
> pvdad4 cdad4 vvdd4 d66d4;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      ppvda1 |     10000    .5773832    .1025367   .0105241    .773866
       pcda1 |     10000    .1430421    .1034168   .0003944   .8688393
       pvvd1 |     10000    .1229365    .0325492   .0276582   .3235207
       pd661 |     10000    .0639232    .0148604   .0139242   .1705652
      ppvda2 |     10000    .3147699    .1089177   .0029793   .7185522
-------------+--------------------------------------------------------
       pcda2 |     10000    .4593759    .0982161   .1199075   .8846253
       pvvd2 |     10000    .0946294    .0265626   .0291735   .2293644
       pd662 |     10000    .0508228    .0147929   .0146045   .1190035
      ppvda3 |     10000    .5231673    .1034765   .0127585   .7216161
       pcda3 |     10000    .3226496    .0762625   .1092407   .8054785
-------------+--------------------------------------------------------
       pvvd3 |     10000    .0609244    .0623014   .0000254   .6836355
       pd663 |     10000    .0358863    .0121438   .0090937   .1126509
      ppvda4 |     10000    .5213715    .1030059   .0144108    .719066
       pcda4 |     10000    .3126373    .0747726   .1123568   .7866305
       pvvd4 |     10000    .0629945    .0193675   .0184134   .1922964
-------------+--------------------------------------------------------
       pd664 |     10000    .0477739    .0529294    .000013    .646144
      pvdad2 |     10000   -.2626134    .1438779  -.6844096    .623239
       cdad2 |     10000    .3163339    .1629273  -.6251834   .8256629
       vvdd2 |     10000   -.0283071    .0286006  -.2051844   .0853551
       d66d2 |     10000   -.0131004    .0136931  -.1071139   .0441354
-------------+--------------------------------------------------------
      pvdad3 |     10000   -.0542159    .0325851  -.2590506   .0831949
       cdad3 |     10000    .1796076    .1217912  -.6276629    .620008
       vvdd3 |     10000    -.062012    .0811382   -.291404   .6231563
       d66d3 |     10000   -.0280369    .0119519  -.1031203   .0169668
      pvdad4 |     10000   -.0560117     .035021   -.261693   .1006526
-------------+--------------------------------------------------------
       cdad4 |     10000    .1695952    .1157458  -.6214491   .6062982
       vvdd4 |     10000    -.059942    .0278608  -.2034383   .0335047
       d66d4 |     10000   -.0161493    .0600053   -.151147   .6084896

. 
end of do-file


. exit, clear
